package 力扣日常刷题.木23一月.第20天320;

import java.util.HashSet;
import java.util.Scanner;

public class Demo99回文指数 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        HashSet<Long> set = new HashSet<>();

        set.add(2L);
        for (long i =3; i < 10000; i++) {
            boolean flag = true;
            for (int j = 2; j < Math.sqrt(i)+1; j++) {
                if(i % j == 0){
                    flag = false;
                    break;
                }
            }
            if(flag) {
                StringBuilder a = new StringBuilder(i+"");
                StringBuilder b = new StringBuilder(a.reverse().toString());
                a.reverse();
                if(a.toString().equals(b.toString())) {
                    set.add(i);
                }
            }
        }


        for (int i = 0; i < n; i++) {
            long t = sc.nextLong();
            if(set.contains(t)){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }

    }
}
